package edu.guigu.servicedemo;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.util.Log;

import androidx.annotation.NonNull;

public class MyMessengerService extends Service {
    private Messenger messenger; // 信使
    private Handler messengerHandel = new Handler() {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            if (msg.what == 1) {
                Log.d("TAG", "handleMessage: 11111111");
            } else if (msg.what == 2) {
                Log.d("TAG", "handleMessage: 2222222222");
            } else {
                Log.d("TAG", "handleMessage: ???????????????");
            }
        }
    };

    public MyMessengerService() {
    }

    @Override
    public void onCreate() {
        super.onCreate();
        messenger = new Messenger(messengerHandel);
    }

    @Override
    public IBinder onBind(Intent intent) {
        return messenger.getBinder();
    }

}